﻿using System;
using System.Web;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using JinianNet.Caching;

namespace JinianNet.Web
{
    public partial class Cache
    {
        public class MemoryCache : ICache
        {
            #region ICache 成员

            public int Count
            {
                get { return HttpRuntime.Cache.Count; }
            }

            public object this[string key]
            {
                get
                {
                    return HttpRuntime.Cache[key];
                }
                set
                {
                    HttpRuntime.Cache[key] = value;
                }
            }

            public object Get(string key)
            {
                return HttpRuntime.Cache.Get(key);
            }

            public void Insert(string key, object value)
            {
                HttpRuntime.Cache.Insert(key, value);
            }

            public void Remove(string key)
            {
                HttpRuntime.Cache.Remove(key);
            }

            public void RemoveAll()
            {
                System.Web.Caching.Cache cache = HttpRuntime.Cache;
                IDictionaryEnumerator CacheEnum = cache.GetEnumerator();
                Stack<string> list = new Stack<string>(cache.Count);
                while (CacheEnum.MoveNext())
                {
                    list.Push(CacheEnum.Key.ToString());
                }
                while (list.Count > 0)
                {
                    cache.Remove(list.Pop());
                }
            }

            #endregion
        }
    }
}
